<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03_JS数据类型</title>
</head>
<body>
    <script>
    //JS数据类型=原始类型+引用类型
    //原始类型：number string boolean null undefined
    var a = 1;
    var b = 9.9;
    console.log(a,b);
    var c ='hello';
    var d ="world";
    console.log(c,typeof c,d,typeof d);
    var e=true;
    var f=false;
    console.log(e,typeof e,f,typeof f);
    var g;
    console.log(g,typeof g);//undefined 'undefined'

    //引用类型Array Object Function Date...
    let obj={};
    console.log(obj,typeof obj);//{} 'object'
    obj.name="杨硕"
    obj.age=18;
    console.log(obj,typeof obj);//{name:'杨硕',age:18} 'object'
    console.log(obj.name);
    console.log(obj.age);

    //自定义对象的写法2
    let obj2={
        name:"杨硕",
        age:18
    }
    console.log(obj2,typeof obj2);//{name:'杨硕',age:18} 'object'
    console.log(obj2.age);
    console.log(obj2.name);
    console.log(obj2.like);//访问对象不存在的属性会得到udefined

    //数组
    let arr=[1,2.4,'3',true];
    console.log(arr,typeof arr);
    console.log(arr[0]);
    console.log(arr[1]);
    console.log(arr[2]);
    console.log(arr[3]);
    console.log(arr[99]);//访问数组不存在的元素会得到udefined

    //Number()将参数转为数值类型,如果无法得到数字类型的结果,就会得到NaN(Not a Number)
    console.log(Number(true),typeof Number(true));//1 number
    console.log(Number(false));//0 number
    console.log(Number('3'));//3
    console.log(Number(3));//3
    console.log(Number(6.6));//6.6
    console.log(Number('哈哈哈'));//NaN

    //Boolean() 将参数转为布尔类型
    //0,NaN,null,undefined,false,''这5个特殊值转为布尔是false
    console.log(Boolean(0));//false
    console.log(Boolean(null));//false
    console.log(Boolean(undefined));//false
    console.log(Boolean(NaN));//false
    console.log(Boolean(''));//false
    console.log(Boolean(' '));//true
    console.log(Boolean('哈哈哈'));//true
    console.log(Boolean('1'));//true
    console.log(Boolean(1));//true
    </script>
</body>
</html>